//
//  GoodsView.m
//  LNH
//
//  Created by twentylx on 2018/1/15.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAGoodsView.h"

@implementation CAGoodsView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params {
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView {
    self.backgroundColor = [UIColor clearColor];
}

/**
 初始化视图
 */
- (void)lm_createViewForView {
    [self addSubview:self.goodsLabel];
    [self addSubview:self.goodsImageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.enterButton];
    [self addSubview:self.lineView];
    
    [self setNeedsUpdateConstraints];
}

#pragma mark layout
- (void) updateConstraints {
    [_goodsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self);
        make.height.mas_equalTo(50);
    }];
    
    [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.goodsLabel.mas_bottom);
//        make.height.mas_equalTo(300);
    }];

    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(self.goodsImageView.mas_bottom).offset(10);
        make.height.mas_equalTo(30);
    }];

    [_enterButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(30);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.bottom.equalTo(self.mas_bottom);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [super updateConstraints];
}

#pragma mark get & set
- (UILabel *) goodsLabel {
    if (!_goodsLabel) {
        _goodsLabel = [UILabel new];
        _goodsLabel.textAlignment = NSTextAlignmentCenter;
        //        _cateTitleLabel.text = @"分类CATEGORY";
        _goodsLabel.font = [UIFont systemFontOfSize:20 weight:1];
        //设置字间距 NSKernAttributeName:@1.5f
        NSDictionary *dic = @{NSKernAttributeName:@3.0f
                              };
        NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:@"优品汇专区" attributes:dic];
        [_goodsLabel setAttributedText:attributedString];
    }
    return _goodsLabel;
}

- (UIImageView *) goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [UIImageView new];
        _goodsImageView.image = LMImageNamed(@"home_goods");
//        _goodsImageView.backgroundColor = [UIColor yellowColor];
        _goodsImageView.contentMode = UIViewContentModeScaleToFill;
    }
    return _goodsImageView;
}

- (UILabel *) titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:16];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
//        _titleLabel.textColor = RGBCOLOR(51, 51, 51);
        //设置字间距 NSKernAttributeName:@1.5f
        NSDictionary *dic = @{NSKernAttributeName:@3.0f
                              };
        NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:@"2018好物优惠推荐" attributes:dic];
        [_titleLabel setAttributedText:attributedString];
    }
    return _titleLabel;
}

- (UIButton *) enterButton {
    if (!_enterButton) {
        _enterButton = [UIButton new];
        [_enterButton setTitle:@"点 击 进 入" forState:UIControlStateNormal];
        [_enterButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _enterButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _enterButton.layer.borderWidth = 1;
//        _enterButton.layer.cornerRadius = 5;
        _enterButton.layer.borderColor = [RGBCOLOR(51, 51, 51) CGColor];
    }
    return _enterButton;
}

- (UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        [_lineView setBackgroundColor:RGBCOLOR(51, 51, 51)];
    }
    return _lineView;
}

@end
